package com.enbatis.mybatisplugs.controller;

import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.service.MongoDbService;
import com.enbatis.mybatisplugs.service.impl.MongoDbServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@RestController
@RequestMapping("v1/oss")
public class MongoDbController extends BaseController {

    @Autowired
    private MongoDbService mongoDbService;


    @GetMapping(value = "/downloadFile")
    public void downloadFile(@RequestParam("file_id") String fileId) {
        mongoDbService.downloadFile(fileId,request,response);
    }


    @PostMapping(value = "/upload")
    public void uploadFile(@RequestParam("businessId") String businessId, @RequestParam("file") MultipartFile file)  {
        mongoDbService.saveFile(file);
    }


    @GetMapping(value = "/preview")
    public void preview(@RequestParam("file_id") String fileId) {
         mongoDbService.preview(fileId,request,response);
    }


}
